package com.lcredu.sqlSeesion;

import com.lcredu.entity.Monster;

import java.lang.reflect.Proxy;

/**
 * @author 黎长容
 * @date 2025-07-28 23:25
 */
public class LcrSqlSession {
    private Executor executor = new LcrExecutor();
    private LcrConfiguration configuration = new LcrConfiguration();

    //封装sqlSession到执行器
    public <T> T selectOne(String statement, Object parameter) {
        Monster monster = executor.queryById(statement, 1);
        return (T) monster;
    }

    //调用动态代理,传入接口的动态代理
    public <T> T getMapper(Class<T> clazz) {
        return (T) Proxy.newProxyInstance(clazz.getClassLoader(), new Class[]{clazz}
                , new LcrMapperProxy(this, configuration, clazz));

    }
}
